using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Diagnostics;
using System.Windows.Forms;

using FreeFlow;
using FreeFlow.Administration;
using FreeFlow.WinFormsControls.HelperClasses;

namespace FreeFlowAdministrator
{
	/// <summary>
	/// Summary description for ServerSettingsControl.
	/// </summary>
	public class ServerSettingsControl : AdminUserControl
  {
    private Label label6;
    private Label label4;
    private PictureBox raisedFlagImage;
    private TextBox eventHandlerFunctionTextBox;
    private Label eventHandlerFunctionLabel;
    private TextBox nameTextBox;
    private PictureBox pictureBox1;
    private Label label7;
    private Label raisedFlaglabel;
    private NumericUpDown sessionTimeoutTextBox;
    private Label label5;
    private CheckBox enableAlertGeneration;
    private NumericUpDown folderLockTimeoutTextBox;
    private CheckBox enableDeletionAlerts;
    private Label label3;
    private TextBox notificationFormulaTextBox;
    private Label databaseTypeLabel;
    private Label notificationFormulaLabel;
    private Label label1;
    private Label label10;
    private Label label2;
    private NumericUpDown keepAliveIntervalTextBox;
    private Label keepAliveIntervalLabel;
    private Label keepAliveMinutesLabel;
    private TextBox guestUserNameTextBox;
    private Label label9;
    private Label schemaVersionLabel;
    private UIActionsControl uiActionsControl;
    private AttachmentsControl attachmentsControl;
    private Panel panel1;
		/// <summary> 
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public ServerSettingsControl()
		{
			// This call is required by the Windows.Forms Form Designer.
			InitializeComponent();

      UIActionList actionList = new UIActionList();
      actionList.Add("Apply changes", "Apply any changes made. Some of these changes may require a restart of the engine", 
        new ActionExecuteDelegate(ApplyChanges));
      actionList.Add("Refresh", "Refresh the data for this server", 
        new ActionExecuteDelegate(RefreshServer));
      actionList.Add("Update blank forms groups", "Update any blank form group to the procedure name if it is set to 'Forms'", 
        new ActionExecuteDelegate(UpdateGroups));
      actionList.Add("Save procedures...", "Retrieve and save the latest versions of all procedures and libraries", 
        new ActionExecuteDelegate(RetrieveProcedures));
      actionList.Add("Run Event Viewer", "View engine messages written to the event log", 
        new ActionExecuteDelegate(RunEventViewer));
      actionList.Add("Maintenance");
      actionList.Add("Delete alerts without a folder", "Remove any alerts for non-existent folders", 
        new ActionExecuteDelegate(DeleteAlerts));
      actionList.Add("Delete events without a folder", "Remove any event entries for non-existent folders", 
        new ActionExecuteDelegate(DeleteEvents));
      actionList.Add("Purge stages", "Remove any stages that are no longer part of procedures and have no folders still at the stage", 
        new ActionExecuteDelegate(PurgeStages));
      actionList.Add("Delete deletion alerts", "Remove deletion alerts older than 30 days old", 
        new ActionExecuteDelegate(DeleteDeletionAlerts));
      actionList.Add("Attachments");
      actionList.Add(attachmentsControl.ActionList);

      uiActionsControl.Actions = actionList;
		}

		/// <summary> 
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Component Designer generated code
		/// <summary> 
		/// Required method for Designer support - do not modify 
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
      System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(ServerSettingsControl));
      this.schemaVersionLabel = new System.Windows.Forms.Label();
      this.label9 = new System.Windows.Forms.Label();
      this.uiActionsControl = new FreeFlowAdministrator.UIActionsControl();
      this.guestUserNameTextBox = new System.Windows.Forms.TextBox();
      this.keepAliveMinutesLabel = new System.Windows.Forms.Label();
      this.keepAliveIntervalLabel = new System.Windows.Forms.Label();
      this.keepAliveIntervalTextBox = new System.Windows.Forms.NumericUpDown();
      this.label2 = new System.Windows.Forms.Label();
      this.label10 = new System.Windows.Forms.Label();
      this.label1 = new System.Windows.Forms.Label();
      this.notificationFormulaLabel = new System.Windows.Forms.Label();
      this.databaseTypeLabel = new System.Windows.Forms.Label();
      this.notificationFormulaTextBox = new System.Windows.Forms.TextBox();
      this.label3 = new System.Windows.Forms.Label();
      this.enableDeletionAlerts = new System.Windows.Forms.CheckBox();
      this.folderLockTimeoutTextBox = new System.Windows.Forms.NumericUpDown();
      this.enableAlertGeneration = new System.Windows.Forms.CheckBox();
      this.label5 = new System.Windows.Forms.Label();
      this.sessionTimeoutTextBox = new System.Windows.Forms.NumericUpDown();
      this.raisedFlaglabel = new System.Windows.Forms.Label();
      this.label7 = new System.Windows.Forms.Label();
      this.pictureBox1 = new System.Windows.Forms.PictureBox();
      this.nameTextBox = new System.Windows.Forms.TextBox();
      this.eventHandlerFunctionLabel = new System.Windows.Forms.Label();
      this.attachmentsControl = new FreeFlowAdministrator.AttachmentsControl();
      this.eventHandlerFunctionTextBox = new System.Windows.Forms.TextBox();
      this.raisedFlagImage = new System.Windows.Forms.PictureBox();
      this.label4 = new System.Windows.Forms.Label();
      this.label6 = new System.Windows.Forms.Label();
      this.panel1 = new System.Windows.Forms.Panel();
      ((System.ComponentModel.ISupportInitialize)(this.keepAliveIntervalTextBox)).BeginInit();
      ((System.ComponentModel.ISupportInitialize)(this.folderLockTimeoutTextBox)).BeginInit();
      ((System.ComponentModel.ISupportInitialize)(this.sessionTimeoutTextBox)).BeginInit();
      ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
      ((System.ComponentModel.ISupportInitialize)(this.raisedFlagImage)).BeginInit();
      this.panel1.SuspendLayout();
      this.SuspendLayout();
      // 
      // schemaVersionLabel
      // 
      this.schemaVersionLabel.Location = new System.Drawing.Point(109, 52);
      this.schemaVersionLabel.Name = "schemaVersionLabel";
      this.schemaVersionLabel.Size = new System.Drawing.Size(192, 16);
      this.schemaVersionLabel.TabIndex = 17;
      this.schemaVersionLabel.Text = "schemaVersionLabel";
      // 
      // label9
      // 
      this.label9.Location = new System.Drawing.Point(5, 122);
      this.label9.Name = "label9";
      this.label9.Size = new System.Drawing.Size(100, 16);
      this.label9.TabIndex = 13;
      this.label9.Text = "Guest user name:";
      // 
      // uiActionsControl
      // 
      this.uiActionsControl.Actions = null;
      this.uiActionsControl.Dock = System.Windows.Forms.DockStyle.Right;
      this.uiActionsControl.Location = new System.Drawing.Point(784, 0);
      this.uiActionsControl.Name = "uiActionsControl";
      this.uiActionsControl.Size = new System.Drawing.Size(168, 695);
      this.uiActionsControl.TabIndex = 21;
      // 
      // guestUserNameTextBox
      // 
      this.guestUserNameTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                  | System.Windows.Forms.AnchorStyles.Right)));
      this.guestUserNameTextBox.Location = new System.Drawing.Point(109, 120);
      this.guestUserNameTextBox.Name = "guestUserNameTextBox";
      this.guestUserNameTextBox.Size = new System.Drawing.Size(668, 20);
      this.guestUserNameTextBox.TabIndex = 14;
      this.guestUserNameTextBox.Text = "guestUserNameTextBox";
      // 
      // keepAliveMinutesLabel
      // 
      this.keepAliveMinutesLabel.Location = new System.Drawing.Point(187, 146);
      this.keepAliveMinutesLabel.Name = "keepAliveMinutesLabel";
      this.keepAliveMinutesLabel.Size = new System.Drawing.Size(48, 16);
      this.keepAliveMinutesLabel.TabIndex = 12;
      this.keepAliveMinutesLabel.Text = "minutes";
      // 
      // keepAliveIntervalLabel
      // 
      this.keepAliveIntervalLabel.Location = new System.Drawing.Point(5, 146);
      this.keepAliveIntervalLabel.Name = "keepAliveIntervalLabel";
      this.keepAliveIntervalLabel.Size = new System.Drawing.Size(100, 16);
      this.keepAliveIntervalLabel.TabIndex = 10;
      this.keepAliveIntervalLabel.Text = "Keep alive interval:";
      // 
      // keepAliveIntervalTextBox
      // 
      this.keepAliveIntervalTextBox.Increment = new decimal(new int[] {
            5,
            0,
            0,
            0});
      this.keepAliveIntervalTextBox.Location = new System.Drawing.Point(109, 144);
      this.keepAliveIntervalTextBox.Maximum = new decimal(new int[] {
            1000,
            0,
            0,
            0});
      this.keepAliveIntervalTextBox.Name = "keepAliveIntervalTextBox";
      this.keepAliveIntervalTextBox.Size = new System.Drawing.Size(72, 20);
      this.keepAliveIntervalTextBox.TabIndex = 11;
      this.keepAliveIntervalTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
      // 
      // label2
      // 
      this.label2.Location = new System.Drawing.Point(5, 32);
      this.label2.Name = "label2";
      this.label2.Size = new System.Drawing.Size(80, 14);
      this.label2.TabIndex = 2;
      this.label2.Text = "Database type:";
      // 
      // label10
      // 
      this.label10.Location = new System.Drawing.Point(5, 52);
      this.label10.Name = "label10";
      this.label10.Size = new System.Drawing.Size(100, 16);
      this.label10.TabIndex = 16;
      this.label10.Text = "Schema version:";
      // 
      // label1
      // 
      this.label1.Location = new System.Drawing.Point(5, 10);
      this.label1.Name = "label1";
      this.label1.Size = new System.Drawing.Size(40, 16);
      this.label1.TabIndex = 0;
      this.label1.Text = "Name:";
      // 
      // notificationFormulaLabel
      // 
      this.notificationFormulaLabel.Location = new System.Drawing.Point(5, 280);
      this.notificationFormulaLabel.Name = "notificationFormulaLabel";
      this.notificationFormulaLabel.Size = new System.Drawing.Size(120, 16);
      this.notificationFormulaLabel.TabIndex = 26;
      this.notificationFormulaLabel.Text = "Notification formula:";
      // 
      // databaseTypeLabel
      // 
      this.databaseTypeLabel.Location = new System.Drawing.Point(109, 32);
      this.databaseTypeLabel.Name = "databaseTypeLabel";
      this.databaseTypeLabel.Size = new System.Drawing.Size(192, 16);
      this.databaseTypeLabel.TabIndex = 3;
      this.databaseTypeLabel.Text = "databaseTypeLabel";
      // 
      // notificationFormulaTextBox
      // 
      this.notificationFormulaTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                  | System.Windows.Forms.AnchorStyles.Right)));
      this.notificationFormulaTextBox.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
      this.notificationFormulaTextBox.Location = new System.Drawing.Point(8, 299);
      this.notificationFormulaTextBox.Multiline = true;
      this.notificationFormulaTextBox.Name = "notificationFormulaTextBox";
      this.notificationFormulaTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
      this.notificationFormulaTextBox.Size = new System.Drawing.Size(769, 72);
      this.notificationFormulaTextBox.TabIndex = 27;
      this.notificationFormulaTextBox.Text = "notificationFormulaTextBox";
      // 
      // label3
      // 
      this.label3.Location = new System.Drawing.Point(5, 74);
      this.label3.Name = "label3";
      this.label3.Size = new System.Drawing.Size(104, 16);
      this.label3.TabIndex = 4;
      this.label3.Text = "Folder lock timeout:";
      // 
      // enableDeletionAlerts
      // 
      this.enableDeletionAlerts.FlatStyle = System.Windows.Forms.FlatStyle.System;
      this.enableDeletionAlerts.Location = new System.Drawing.Point(8, 377);
      this.enableDeletionAlerts.Name = "enableDeletionAlerts";
      this.enableDeletionAlerts.Size = new System.Drawing.Size(127, 16);
      this.enableDeletionAlerts.TabIndex = 28;
      this.enableDeletionAlerts.Text = "Enable deletion alerts";
      // 
      // folderLockTimeoutTextBox
      // 
      this.folderLockTimeoutTextBox.Increment = new decimal(new int[] {
            10,
            0,
            0,
            0});
      this.folderLockTimeoutTextBox.Location = new System.Drawing.Point(109, 72);
      this.folderLockTimeoutTextBox.Maximum = new decimal(new int[] {
            1000,
            0,
            0,
            0});
      this.folderLockTimeoutTextBox.Name = "folderLockTimeoutTextBox";
      this.folderLockTimeoutTextBox.Size = new System.Drawing.Size(72, 20);
      this.folderLockTimeoutTextBox.TabIndex = 5;
      this.folderLockTimeoutTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
      // 
      // enableAlertGeneration
      // 
      this.enableAlertGeneration.FlatStyle = System.Windows.Forms.FlatStyle.System;
      this.enableAlertGeneration.Location = new System.Drawing.Point(150, 377);
      this.enableAlertGeneration.Name = "enableAlertGeneration";
      this.enableAlertGeneration.Size = new System.Drawing.Size(144, 16);
      this.enableAlertGeneration.TabIndex = 29;
      this.enableAlertGeneration.Text = "Enable alert generation";
      // 
      // label5
      // 
      this.label5.Location = new System.Drawing.Point(5, 98);
      this.label5.Name = "label5";
      this.label5.Size = new System.Drawing.Size(100, 16);
      this.label5.TabIndex = 7;
      this.label5.Text = "Session timeout:";
      // 
      // sessionTimeoutTextBox
      // 
      this.sessionTimeoutTextBox.Increment = new decimal(new int[] {
            10,
            0,
            0,
            0});
      this.sessionTimeoutTextBox.Location = new System.Drawing.Point(109, 96);
      this.sessionTimeoutTextBox.Maximum = new decimal(new int[] {
            1440,
            0,
            0,
            0});
      this.sessionTimeoutTextBox.Name = "sessionTimeoutTextBox";
      this.sessionTimeoutTextBox.Size = new System.Drawing.Size(72, 20);
      this.sessionTimeoutTextBox.TabIndex = 8;
      this.sessionTimeoutTextBox.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
      // 
      // raisedFlaglabel
      // 
      this.raisedFlaglabel.Location = new System.Drawing.Point(30, 167);
      this.raisedFlaglabel.Name = "raisedFlaglabel";
      this.raisedFlaglabel.Size = new System.Drawing.Size(742, 16);
      this.raisedFlaglabel.TabIndex = 31;
      this.raisedFlaglabel.Text = "There are more than 10 flags waiting to be processed. This may indicate a problem" +
          " with the eRaisedFlag table";
      // 
      // label7
      // 
      this.label7.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
      this.label7.Location = new System.Drawing.Point(8, 396);
      this.label7.Name = "label7";
      this.label7.Size = new System.Drawing.Size(100, 16);
      this.label7.TabIndex = 19;
      this.label7.Text = "Attachments";
      // 
      // pictureBox1
      // 
      this.pictureBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
      this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
      this.pictureBox1.Location = new System.Drawing.Point(745, 10);
      this.pictureBox1.Name = "pictureBox1";
      this.pictureBox1.Size = new System.Drawing.Size(32, 32);
      this.pictureBox1.TabIndex = 32;
      this.pictureBox1.TabStop = false;
      // 
      // nameTextBox
      // 
      this.nameTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                  | System.Windows.Forms.AnchorStyles.Right)));
      this.nameTextBox.Location = new System.Drawing.Point(109, 8);
      this.nameTextBox.Name = "nameTextBox";
      this.nameTextBox.Size = new System.Drawing.Size(630, 20);
      this.nameTextBox.TabIndex = 1;
      this.nameTextBox.Text = "nameTextBox";
      // 
      // eventHandlerFunctionLabel
      // 
      this.eventHandlerFunctionLabel.Location = new System.Drawing.Point(5, 186);
      this.eventHandlerFunctionLabel.Name = "eventHandlerFunctionLabel";
      this.eventHandlerFunctionLabel.Size = new System.Drawing.Size(184, 16);
      this.eventHandlerFunctionLabel.TabIndex = 33;
      this.eventHandlerFunctionLabel.Text = "Event handler function:";
      // 
      // attachmentsControl
      // 
      this.attachmentsControl.Dock = System.Windows.Forms.DockStyle.Fill;
      this.attachmentsControl.Location = new System.Drawing.Point(0, 417);
      this.attachmentsControl.Name = "attachmentsControl";
      this.attachmentsControl.Size = new System.Drawing.Size(784, 278);
      this.attachmentsControl.TabIndex = 18;
      // 
      // eventHandlerFunctionTextBox
      // 
      this.eventHandlerFunctionTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
                  | System.Windows.Forms.AnchorStyles.Right)));
      this.eventHandlerFunctionTextBox.Font = new System.Drawing.Font("Courier New", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
      this.eventHandlerFunctionTextBox.Location = new System.Drawing.Point(8, 205);
      this.eventHandlerFunctionTextBox.Multiline = true;
      this.eventHandlerFunctionTextBox.Name = "eventHandlerFunctionTextBox";
      this.eventHandlerFunctionTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
      this.eventHandlerFunctionTextBox.Size = new System.Drawing.Size(769, 72);
      this.eventHandlerFunctionTextBox.TabIndex = 34;
      this.eventHandlerFunctionTextBox.Text = "eventHandlerFunctionTextBox";
      // 
      // raisedFlagImage
      // 
      this.raisedFlagImage.Image = ((System.Drawing.Image)(resources.GetObject("raisedFlagImage.Image")));
      this.raisedFlagImage.Location = new System.Drawing.Point(8, 167);
      this.raisedFlagImage.Name = "raisedFlagImage";
      this.raisedFlagImage.Size = new System.Drawing.Size(16, 16);
      this.raisedFlagImage.TabIndex = 30;
      this.raisedFlagImage.TabStop = false;
      // 
      // label4
      // 
      this.label4.Location = new System.Drawing.Point(187, 74);
      this.label4.Name = "label4";
      this.label4.Size = new System.Drawing.Size(48, 16);
      this.label4.TabIndex = 6;
      this.label4.Text = "minutes";
      // 
      // label6
      // 
      this.label6.Location = new System.Drawing.Point(187, 98);
      this.label6.Name = "label6";
      this.label6.Size = new System.Drawing.Size(48, 16);
      this.label6.TabIndex = 9;
      this.label6.Text = "minutes";
      // 
      // panel1
      // 
      this.panel1.Controls.Add(this.databaseTypeLabel);
      this.panel1.Controls.Add(this.label6);
      this.panel1.Controls.Add(this.notificationFormulaTextBox);
      this.panel1.Controls.Add(this.label3);
      this.panel1.Controls.Add(this.label4);
      this.panel1.Controls.Add(this.notificationFormulaLabel);
      this.panel1.Controls.Add(this.raisedFlagImage);
      this.panel1.Controls.Add(this.enableDeletionAlerts);
      this.panel1.Controls.Add(this.label1);
      this.panel1.Controls.Add(this.eventHandlerFunctionTextBox);
      this.panel1.Controls.Add(this.folderLockTimeoutTextBox);
      this.panel1.Controls.Add(this.nameTextBox);
      this.panel1.Controls.Add(this.label10);
      this.panel1.Controls.Add(this.eventHandlerFunctionLabel);
      this.panel1.Controls.Add(this.enableAlertGeneration);
      this.panel1.Controls.Add(this.schemaVersionLabel);
      this.panel1.Controls.Add(this.label2);
      this.panel1.Controls.Add(this.label9);
      this.panel1.Controls.Add(this.label5);
      this.panel1.Controls.Add(this.pictureBox1);
      this.panel1.Controls.Add(this.keepAliveIntervalTextBox);
      this.panel1.Controls.Add(this.guestUserNameTextBox);
      this.panel1.Controls.Add(this.sessionTimeoutTextBox);
      this.panel1.Controls.Add(this.label7);
      this.panel1.Controls.Add(this.keepAliveIntervalLabel);
      this.panel1.Controls.Add(this.keepAliveMinutesLabel);
      this.panel1.Controls.Add(this.raisedFlaglabel);
      this.panel1.Dock = System.Windows.Forms.DockStyle.Top;
      this.panel1.Location = new System.Drawing.Point(0, 0);
      this.panel1.Name = "panel1";
      this.panel1.Size = new System.Drawing.Size(784, 417);
      this.panel1.TabIndex = 35;
      // 
      // ServerSettingsControl
      // 
      this.Controls.Add(this.attachmentsControl);
      this.Controls.Add(this.panel1);
      this.Controls.Add(this.uiActionsControl);
      this.Name = "ServerSettingsControl";
      this.Size = new System.Drawing.Size(952, 695);
      ((System.ComponentModel.ISupportInitialize)(this.keepAliveIntervalTextBox)).EndInit();
      ((System.ComponentModel.ISupportInitialize)(this.folderLockTimeoutTextBox)).EndInit();
      ((System.ComponentModel.ISupportInitialize)(this.sessionTimeoutTextBox)).EndInit();
      ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
      ((System.ComponentModel.ISupportInitialize)(this.raisedFlagImage)).EndInit();
      this.panel1.ResumeLayout(false);
      this.panel1.PerformLayout();
      this.ResumeLayout(false);

    }
		#endregion

    private Server server;
    public void LoadServerSettings(Server server)
    {
      this.server = server;
      nameTextBox.Text = server.Name;
      databaseTypeLabel.Text = EnumDescription.GetDescription(server.DatabaseType);
      folderLockTimeoutTextBox.Text = server.FolderLockTimeout.ToString();
      sessionTimeoutTextBox.Text = server.SessionTimeout.ToString();
      guestUserNameTextBox.Text = server.GuestUserName;
      schemaVersionLabel.Text = EnumDescription.GetDescription(server.SchemaVersion);

      // version 6.6
      // keep alive interval
      keepAliveIntervalTextBox.Text = server.KeepAliveInterval.ToString();
      keepAliveIntervalLabel.Visible = (server.SchemaVersion >= SchemaVersion.Version66);
      keepAliveIntervalTextBox.Visible = (server.SchemaVersion >= SchemaVersion.Version66);
      keepAliveMinutesLabel.Visible = (server.SchemaVersion >= SchemaVersion.Version66);

      // version 7.0
      // notification formula
      notificationFormulaLabel.Visible = (server.SchemaVersion >= SchemaVersion.Version70);
      notificationFormulaTextBox.Visible = (server.SchemaVersion >= SchemaVersion.Version70);
      notificationFormulaTextBox.Text = server.NotificationFormula;

      // version 7.01
      enableDeletionAlerts.Visible = (server.SchemaVersion >= SchemaVersion.Version701);
      enableDeletionAlerts.Checked = server.EnableDeletionAlerts;
      enableAlertGeneration.Visible = (server.SchemaVersion >= SchemaVersion.Version701);
      enableAlertGeneration.Checked = server.EnableAlertGeneration;

      // version 7.5
      eventHandlerFunctionLabel.Visible = (server.SchemaVersion >= SchemaVersion.Version75);
      eventHandlerFunctionTextBox.Visible = (server.SchemaVersion >= SchemaVersion.Version75);
      eventHandlerFunctionTextBox.Text = server.EventHandlerFunction;

      attachmentsControl.LoadAttachments(server.Attachments);

      // raised flag warning
      int raisedFlagsPending = server.RaisedFlagsPending; 
      raisedFlagImage.Visible = raisedFlagsPending > 10;
      raisedFlaglabel.Visible = raisedFlagsPending > 10;
    }

    private string ApplyChanges()
    {
      using (new CursorHandler())
      {
        server.Name = nameTextBox.Text;
        server.FolderLockTimeout = (int)folderLockTimeoutTextBox.Value;
        server.SessionTimeout = (int)sessionTimeoutTextBox.Value;
        server.GuestUserName = guestUserNameTextBox.Text;
        server.KeepAliveInterval = (int)keepAliveIntervalTextBox.Value;
        server.NotificationFormula = notificationFormulaTextBox.Text;
        server.EnableDeletionAlerts = enableDeletionAlerts.Checked;
        server.EnableAlertGeneration = enableAlertGeneration.Checked;
        server.EventHandlerFunction = eventHandlerFunctionTextBox.Text;
        server.ApplyChanges();
        return Constants.ChangesApplied;
      }
    }

    private string RefreshServer()
    {
      server.Refresh();
      LoadServerSettings(server);
      return null;
    }

    private string DeleteAlerts()
    {
      int recordsDeleted;
      using (new CursorHandler())
      {
        recordsDeleted = server.DeleteAlertsWithoutFolder();
      }
      return recordsDeleted + " alerts deleted";
    }

    private string DeleteEvents()
    {
      int recordsDeleted;
      using (new CursorHandler())
      {
        recordsDeleted = server.DeleteEventsWithoutFolder();
      }
      return recordsDeleted + " events deleted";
    }

    private string DeleteDeletionAlerts()
    {
      int recordsDeleted;
      using (new CursorHandler())
      {
        recordsDeleted = server.DeleteDeletionAlerts(30);
      }
      return recordsDeleted.ToString() + " deletion alerts deleted";
    }

    private string UpdateGroups()
    {
      using (new CursorHandler())
      {
        server.UpdateBlankFormsGroups();
      }
      return null;
    }

    private string PurgeStages()
    {
      int count;
      using (new CursorHandler())
      {
        count = server.PurgeStages();
      }
      return count + " stages purged";
    }

    private string RetrieveProcedures()
    {
      using (FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog())
      {
        if (folderBrowserDialog.ShowDialog() == DialogResult.OK)
        {
          using(new CursorHandler())
          {
            if (server != null)
              server.RetrieveLatestProcedures(folderBrowserDialog.SelectedPath);
          }
        }
      }
      return null;
    }

    private string RunEventViewer()
    {
      Process.Start("eventvwr.msc");
      return "";
    }
	}
}
